<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once("database.php");

	class follower_handler extends database{

            public $result;

            function  __construct() {
                parent::__construct();
            }

            function  __destruct() {

            }
            

            function add_follower($usr_id, $usr_fol){
                $query = "INSERT INTO usr_followers VALUES('$usr_id','$usr_fol')";
				$this->connect();
				mysql_query($query,$this->conn);
				mysql_close();
            }


            function retr_follower($usr_id){
                $query = "SELECT usr_follower FROM usr_followers WHERE usr_email='$usr_id'";
				$res = $this->exec_q($query, "usr_follower");
                $this->result = $res;
                //hasil = $this->result[idx]
            }

            function del_follower($usr_id, $usr_fol){
                $query = "DELETE FROM usr_followers WHERE usr_email='$usr_id' AND usr_follower='$usr_fol'";
				$this->connect();
				mysql_query($query,$this->conn);
				mysql_close();
            }
			
			function del_allfollower($usr_id){
                $query = "DELETE FROM usr_followers WHERE usr_email='$usr_id'";
				$this->connect();
				mysql_query($query,$this->conn);
				mysql_close();
            }
			
			function del_allfollowing($usr_id){
                $query = "DELETE FROM usr_followers WHERE usr_follower='$usr_id'";
				$this->connect();
				mysql_query($query,$this->conn);
				mysql_close();
            }
			
			function retr_following($usr_id) {
			    $query = "SELECT usr_email FROM usr_followers WHERE usr_follower='$usr_id'";
                $res = $this->exec_q($query, "usr_email");
                $this->result = $res;
			}

            function is_follow($usr_current, $usr_other){
                $q = "SELECT * FROM usr_followers WHERE usr_follower='$usr_current' AND usr_email='$usr_other'";
                $this->connect();
                $res = mysql_query($q, $this->conn);

                if (mysql_num_rows($res) > 0) return true;
                else return false;

                mysql_close();
            }


        }

?>